import {computed, onMounted, ref} from 'vue'
import {defineStore} from 'pinia'
import * as enchantmentApi from "@/api/enchantment.js"
import { selectItemStore } from "@/stores/SelectItem.js";

export const tableDataStore = defineStore('tableData', () => {
    const selectItemStr = selectItemStore()
    const enchantmentData = ref([])
    const enchantment = ref({
        displayName: "",
        type: "",
        targets: [],
        rarity: "",
        tradeable: null,
        discoverable: null,
        enchantable: null,
        sortBo:{raritySort:-1}
    })

    async function getData() {
        enchantment.value.targets = targets.value
        const res = await enchantmentApi.list(enchantment.value)
        enchantmentData.value = res.data
    }

    async function log() {
        console.log(targets.value)
    }

    const targets = computed(() => selectItemStr.list.filter(item => item.select === true).map(item => item.value))

    return {
        enchantmentData,
        getData,
        enchantment,
        log
    }
})
